import sys
import os
import os.path
import string

def retrieve_mean(content):
	for line in xrange(len(content)-1, 0, -1):
		if content[line].find("Standard") != -1:
			sd = float(content[line].split()[3].replace(",",".")) #recuperando o valor de desvio padrao
			mean = float(content[line-1].split()[2].replace(",",".")) #recuperando o valor da media
			return (mean,sd)
	return None

csv_file = ""

base_dir = '.'
if len(sys.argv) > 1:
	base_dir = sys.argv[1]

for dir in os.listdir(base_dir):
	if not os.path.isdir(os.path.join(base_dir, dir)):
		continue
	print dir
	file = open(dir + os.sep + "output.txt", 'r')
	content = file.readlines()
	file.close()
	
	mean,sd = retrieve_mean(content)
	high = mean + sd
	low = mean - sd
	csv_file += dir + "," + str(mean) + "," + str(high) + "," + str(low) + "," + str(mean) + "\n"
	
		
file = open("execution_time.csv", "w")
file.write(csv_file)
file.close()